//
//  UIButton+RxExtection.swift
//  YKSwiftRxExtection
//
//  Created by edward on 2022/1/11.
//

import UIKit
import RxSwift


extension Reactive where Base: UIButton {
    
    public func enabled() -> Binder<Bool> {
        Binder(self.base) { button, enabled in
            button.isEnabled = enabled
        }
    }
    
    public func selected() -> Binder<Bool> {
        Binder(self.base) { button, selected in
            button.isSelected = selected
        }
    }
    
    public func fontSize(_ weight: UIFont.Weight = .regular) -> Binder<CGFloat> {
        Binder(self.base) { base, size in
            base.titleLabel?.font = UIFont.systemFont(ofSize: size,weight: weight)
        }
    }
    
    public func titleColor(for controlState: UIControl.State = []) -> Binder<UIColor?> {
        Binder(self.base) { base, color in
            base.setTitleColor(color, for: controlState)
        }
    }
}
